#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int main(int argc, char * argv[])
{
	FILE * fp_src, * fp_dst;
	int ch;
	//参数检验
	if(argc < 3)
	{
		fprintf(stderr, "Usage:%s <src file name> <dst file name>\n", argv[0]);
		exit(1);
	}
	//打开两个文件
	fp_src = fopen(argv[1], "r");
	if(fp_src == NULL)
	{
		perror("fopen failed");
		exit(1);
	}
	fp_dst = fopen(argv[2], "w");
	if(fp_dst == NULL)
	{
		perror("fopen failed");
		exit(1);
	}
	//循环
	while(1)
	{
		//读一个字符 >>> 存储进ch变量
		ch = fgetc(fp_src);
		//如果返回值为EOF就跳出循环
		if(ch == EOF)
			break;
		else
			fputc(ch, fp_dst);
	}
	//关闭文件
	fclose(fp_dst);
	fclose(fp_src);

	exit(0);
}
